package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.PurchaseBean;
import com.project.service.IPurchaseService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * @author lyl
 * description:
 */
@RestController
@RequestMapping("purchase")
@Api(tags = "采购信息查询controller")
public class PurchaseController {
    @Autowired
    private IPurchaseService iPurchaseService;

    @GetMapping("showByPage/{pageNum}/{supplierName}/{startDate}/{endDate}")
    private PageInfo<PurchaseBean> showPurchaseByPage(@PathVariable int pageNum,
                                                      @PathVariable String supplierName,
                                                      @PathVariable String startDate,
                                                      @PathVariable String endDate) {
        if ("1".equals(supplierName)) {
            supplierName = null;
        }
        return iPurchaseService.showInfoByPage(pageNum, supplierName, LocalDate.parse(startDate), LocalDate.parse(endDate));
    }


    @GetMapping("findPurchaseById/{purchaseId}")
    private PurchaseBean findPurchaseById(@PathVariable int purchaseId) {
        return iPurchaseService.findPurchaseById(purchaseId);
    }

}
